<?php
$this->menu = array(
	array('label'=>'新建枚举类型', 'url'=>array('edit'), 'visible'=>Yii::app()->user->v('manage@EnumsEdit')),
);
$cs = Yii::app()->clientScript;
$cs->registerScriptFile(BASE_URL . '/js/jquery_plus/jquery.form.js', CClientScript::POS_END);
$cs->registerCss('edit', 
	'.y_table{width:90%;margin-left:10px;}
	.y_table td{padding:4px 8px;}
	.y_table td.opts .button{background:#42A2E2;}'
);
?>
<h2><a href="/manage/Enums/admin">枚举管理列表</a> > 枚举编辑</h2>
<?php 
$this->beginWidget('CActiveForm', array(
	'id'			=> 'enum_cate_form',
	'htmlOptions' 	=> array('class'=>'setting_form'),
));
?>
	<div class="setting_nav"></div>
	<dl class="setting_content">
		<dt>基本信息</dt>
		<dd>
			<strong>枚举名称：</strong>
			<?php echo YHtml::activeTextField($model, 'name', array('model'=>'Enum', 'rule'=>'^.{1,50}$', 'next_focus'=>''))?>
			<p>枚举类型名称，可以用于备注，不作为其它作用</p>
		</dd>
		<dd>
			<strong>枚举编码：</strong>
			<?php echo YHtml::activeTextField($model, 'code', array('model'=>'Enum', 'rule'=>'^[_|a-z|A-Z|0-9]{1,50}$', 'next_focus'=>''))?>
			<p>用于模块调用，请使用字母、数字及下划线，不可重复</p>
		</dd>
		<dt>枚举值</dt>
		<dd>
			<table class="y_table">
				<tr>
					<th>枚举值</th>
					<th>枚举名称</th>
					<th>操作</th>
				</tr>
				<?php if(!isset($model['items']) || empty($model['items'])){?>
				<tr class="row">
					<td>
						<input type="text" name="EnumValues[]" class="enum_value_input" rule="^\d+$" next_focus/>
					</td>
					<td>
						<input type="text" name="EnumNames[]" class="enum_name_input" rule="^.+$" next_focus/>
					</td>
					<td>
						<a href="javascript:void(0)" class="del_btn">删除</a>
					</td>
				</tr>
				<?php 
				}else{
					//有值时
					foreach ($model['items'] as $val=>$name){
				?>
				<tr class="row">
					<td>
						<input type="text" name="EnumValues[]" class="enum_value_input" value="<?php echo $val?>" rule="^\d+$" next_focus/>
					</td>
					<td>
						<input type="text" name="EnumNames[]" class="enum_name_input" value="<?php echo $name?>" rule="^.+$" next_focus/>
					</td>
					<td>
						<a href="javascript:void(0)" class="del_btn">删除</a>
					</td>
				</tr>
				<?php 
					}
				?>
				<?php }?>
				<tr>
					<td colspan="3" class="right opts">
						<input type="button" class="button add_btn" value="添加"/>
					</td>
				</tr>
			</table>
		</dd>
	</dl>
	<div class="buttons right">
		<?php echo YHtml::activeHiddenField($model, '_id', array('model'=>'Enum'))?>
		<input type="button" class="button save_btn" value="保存"/>
	</div>
<?php $this->endWidget(); ?>